<?php 
        include_once $_SERVER['DOCUMENT_ROOT'].'/functions/password/bdd.php';
	include_once($_SERVER['DOCUMENT_ROOT'].'/functions/affichage/liste.php');
	try {
		$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
		$bdd = new PDO('mysql:host=localhost;dbname=origavion', 'origavion', get_bdd_password(), $pdo_options);
	} catch (Exception $e) {
		die($e->getmessage());
	}
	if (isset($_GET['search'])){
		if (isset($_GET['cat'])){
			$reponse = $bdd->prepare('SELECT * FROM avion WHERE nom = ? OR description = ? AND cat = ? ORDER BY date_de_post DESC  LIMIT 0,10');
			$reponse->execute(array($_GET['search'], $_GET['search'], $_GET['cat']));
		} else {
			$reponse = $bdd->prepare('SELECT * FROM avion WHERE nom = ? OR description = ? ORDER BY date_de_post DESC  LIMIT 0,10');
			$reponse->execute(array($_GET['search'], $_GET['search']));
		}
	} else if (isset($_GET['cat'])){
		$reponse = $bdd->prepare('SELECT * FROM avion WHERE cat = ? ORDER BY date_de_post DESC  LIMIT 0,10');
		$reponse->execute(array($_GET['cat']));
	} else {
		$reponse = $bdd->query('SELECT * FROM avion ORDER BY date_de_post DESC LIMIT 0,10');
	}
	
	afficheResults($reponse);
	$reponse->closeCursor();
?>